package com.youu.youu.restapi.service.impl;

import com.atguigu.util.CommonUtils;
import com.youu.youu.manager.bean.TBlog;
import com.youu.youu.manager.dao.TBlogMapper;
import com.youu.youu.restapi.service.BlogService;
import com.youu.youu.restapi.service.MessageService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * @author cc
 * @create 2017-08-14 16:28
 * @desc 博文服务层的实现类
 **/
@Service
public class BlogServiceImpl implements BlogService {

    @Autowired
    TBlogMapper tBlogMapper;
    
    @Autowired
    MessageService messageService;

    @Override
    public boolean removeBlog(Integer blogId) {

        int flat = tBlogMapper.deleteByPrimaryKey(blogId);
        if (flat == 0){
            return false;
        }

        return true;

    }

    /**
     * 保存博文
     * @author cc
     * @param tBlog
     * @return
     */
    @Override
    public boolean saveBlog(TBlog tBlog) {

        //System.out.println(tBlog);
        int flat = tBlogMapper.insertSelective(tBlog);
        if (flat == 0){
            return false;
        }
        return true;
    }

    /**
     * 读取博文
     * @param id
     * @return
     */
    @Override
    public TBlog getBlog(Integer id) {
        TBlog tBlog = tBlogMapper.selectByPrimaryKey(id);

        return tBlog;
    }

    /**
     * 根据用户Id，获取他的所有博文
     * @param userId
     * @return
     */
    @Override
    public List<TBlog> showBlogList(Integer userId) {
        List<TBlog> tBlogs = tBlogMapper.backwardShowBlogById(userId);
        //System.out.println(tBlogs);
        return tBlogs;
    }



}
